-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.txt
113 lines (93 loc) · 3.37 KB
/
parser.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Jack statement examples: ifStatement | whileStatement | letStatement
statements: statement* ('*': 0 or more)
ifStatemtent: 'if' '('expression')'
'{'statements'}'
whileStatement: 'while' '('expressin')'
'{'statements'}'
letStatement: 'let' varName(identifier) '=' expression ';'
expression: term (operator term)? ('?': o or 1)
term: varName | constant
varName: string not bigining with a digit.
constant: a decimle number
operator: '+' | '-' | '=' | '<' | '>'
xml of this expressiong: count + 1
<expression>
<term>
<identfier> count </identifier>
</term>
<symbol> + </symbol>
<term>
<integerConstant> 1 </integerConstrant>
</term>
</expression>
In unit 4.5 in 0:41 there are a more complex example for xml result of parsing Jack code.
< ____Parser SudoCode____ >
class CompilationEngine
{
compileStatements()
{// code for compiling statements}
compleIfStatement()
{// code for compiling if statement}
comileWhileStatement()
{// code for compiling an while statement}
compileLetStatement()
{...}
compileTerm()
{...}
}
< _______________________ >
Parser work stemulation in unit 4.5 in 5:09.
####4.6: More datail in Jack grammer####
=> Jack Grammer: program structure
-> Jack program is a collection of classes.
-> Each class apearing in seperate file.
-> Each file compiles seprately.
-> class structure:
'class' className '{' classVarDec* subroutineDec* '}'
-> classVarDec structure:
('static'|'field') type varName (',' varName)* ';'
-> type structure: 'int'|'char'|'boolean'|className
-> subroutineDec structure:
('constructor'|'function'|'method') ('void'|type) subroutineName '('parameterList')' subroutineBody
-> parameterList structure: ((type varName) (',' type varName)*)?
-> SubroutineBody structure: '{'varDec* statements'}'
-> varDec structure: 'var' type varName (',' varName)*;
-> className: identfire;
-> subroutineName: identifire;
-> varName: identifire;
=> Jack Grammer: jack program include statements as follow:
-> statements structure: statement*
-> statement: letStatement|ifStatement|whileStatement|doStatement|returnStatement
-> letStatement Structure: 'let' varName('['expression']')? '=' expression';'
-> ifStatement structure: 'if' '('expression')''{'statements'}' ('else''{'statements'}')?
-> whileStatement structure: 'while' '('expression')' '{'statements'}'
-> doStatement structure: 'do' subroutineCall';'
-> returnStatement structure: 'return' expression?';'
=> Jack Grammer: jack program include expressions as follow:
-> expression structure: term (operation term)* |Another translation: expression structure: term (operation expression)*
-> term: integerConstant|stringConstant|keywordConstant|varName|varName'['expression']'|subroutineCall|
'('expression')'|unaryOperation term
-> subroutineCall structure: subroutineName'('expressionList')'|
(className|varName)'.'subroutineName'('expressionList')'
-> expressionList structure: (expression(','expression)*)?
-> operation: '+'|'-'|'*'|'/'|'&'|'|'|'>'|'='|'<'
-> unaryOperation: '~'|'-'
-> keywordConstant: 'true'|'false'|'this'|'null'
<_____________>
There is an more complex example of xml code resulting from the parser in unit 4.7 in 3:35
The non-terminal tags you can use in xml code:
- class
- classVarDec
- subroutineDec
- parameterList
- subroutineBody
- varDec
- statements
- letStatement
- ifStatement
- whileStatement
- doStatement
- returnStatement
- expression
- term
- expressionList