source: proto/pablo/input/grammar/scatter/pablo.scatter.beta @ 2370

Last change on this file since 2370 was 2370, checked in by ksherdy, 7 years ago

Cleaned up old grammars.

File size: 3.8 KB
Line 
1
2// 1. insert curlies in pythodn code to mark code blocks.
3
4context main {
5 recognizers {
6         Whitespace [IGNORE],
7         Integer [INTEGER_CONST],
8         Identifier [IDENTIFIER],        // note: java identifiers. This also produces LextantTokens for keywords.
9         Comment [IGNORE] "#" "\n",
10         Comment [SQ_STRING] "'" "'",
11         Comment [IGNORE] "/***" "***/",                 // comment for commenting-out sections of code during debugging of this grammar.
12         String [STRING],
13         Punctuator,
14         EndOfInput,
15 }
16
17 tokens {
18         IF,
19         ELSE,
20         ELIF,
21         WHILE,
22         CLASS,
23         IMPORT,
24         DEF,
25         
26         DOT ".",
27         COLON ":",
28         COMMA ",",
29         TERMINATOR ";",
30         
31         LEFTROUND "(", RIGHTROUND ")",
32//               LEFTSQUARE "[", RIGHTSQUARE "]",
33         LEFTCURLY "{", RIGHTCURLY "}",
34
35         OR "|",
36         OR_EQUAL "|=",
37         XOR "^",
38         XOR_EQUAL "^=",
39         AND "&",
40         AND_EQUAL "&=",
41         NOT "~",
42         MINUS "-",
43         PLUS "+",
44         ASSIGN "=",
45 }
46}
47
48
49interfaces {
50//       escapable {boolean escaped = false;},
51}
52
53nodes {
54 binaryOperator {} [expression, expression1, expression3],
55 unaryOperator {} [expression2],
56 assignment {} [assignmentStatementRest],
57 ifStatement {} [ifStatementBulk],
58 functionInvocation {} [functionInvocationRest],
59 ASTNode [assignmentOrFunctionInvocation, variableOrFunctionInvocation],
60}
61
62grammar {
63 start → (import | structDeclaration | functionDef )*;
64 
65 import -> IMPORT identifier ;
66 
67 
68 ////////////////////////////////////////////////////////////////////////
69 // classes in python are used for structs in pablo.
70 // We need to put curly braces {} around body of class delcaration.
71 // this grammar only allows simple initialization of fields as class
72 // body statements. Verfiy this as a property of the input.
73 ////////////////////////////////////////////////////////////////////////
74 
75 structDeclaration → CLASS structName LEFTROUND RIGHTROUND COLON structBody ;
76 structBody → LEFTCURLY structBodyStatement* RIGHTCURLY ;
77 structBodyStatement ʉ → variableName ASSIGN value TERMINATOR? ;
78 value → INTEGER_CONST ;
79 
80 
81 
82 ////////////////////////////////////////////////////////////////////////
83 // functions.
84 // We need to put curly braces {} around body of function delcaration,
85 // and any if or else or while.
86 //
87 ////////////////////////////////////////////////////////////////////////
88 
89 functionDef → DEF functionName LEFTROUND parameterList RIGHTROUND COLON blockStatement ;
90 parameterList → identifier ( COMMA identifier )* ;
91 
92 statement ʉ → (assignmentOrFunctionInvocation | ifStatement | whileStatement | blockStatement) TERMINATOR?;
93 blockStatement → LEFTCURLY statement* RIGHTCURLY ;
94 
95 assignmentOrFunctionInvocation → compoundVariable ( assignmentStatementRest ▲ | functionInvocationRest ▲ ) ;
96 assignmentStatementRest → assignOp^! expression ;
97 assignOp -> AND_EQUAL | OR_EQUAL | XOR_EQUAL | ASSIGN ;
98 
99 ifStatement ʉ → IF ifStatementBulk ;
100 ifStatementBulk → expression COLON? blockStatement (ELIF COLON? ifStatementBulk | ELSE COLON? blockStatement)? ;
101 whileStatement → WHILE expression COLON? blockStatement ;
102 expressionStatement → expression;
103 
104 expression ʉ → expression1 ( (OR^ | XOR^) expression )? ;    // lowest precedence: OR, XOR
105 expression1 ʉ → expression2 ( AND^ expression1 )? ;          //      AND
106 expression2 ʉ → NOT^^? expression3 ;
107 expression3 ʉ → expression4 ( (MINUS^ | PLUS^) expression3 )? ◄;
108 expression4 ʉ → LEFTROUND expression RIGHTROUND
109 
110              | variableOrFunctionInvocation
111 
112              | constant ;
113 
114 variableOrFunctionInvocation ʉ → compoundVariable (functionInvocationRest ▲)? ;
115 functionInvocationRest → LEFTROUND^ expression (COMMA expression)* RIGHTROUND ;
116 
117 compoundVariable ʉ → identifier (DOT^ identifier)* ;
118 constant -> STRING | SQ_STRING | INTEGER_CONST ;
119 
120 structName ʉ → identifier ;
121 variableName ʉ → identifier ;
122 functionName ʉ → identifier ;
123 identifier → IDENTIFIER ;
124 
125}
Note: See TracBrowser for help on using the repository browser.