Commit 88c33ae694d8a8b22b5add704140e66876750b01
1 parent
877ad521
*** empty log message ***
Showing
3 changed files
with
37 additions
and
28 deletions
Show diff stats
anubis_dev/library/syntactic_analysis/calculator.apm
| ... | ... | @@ -19,6 +19,7 @@ define Int32 |
| 19 | 19 | |
| 20 | 20 | #calc_parser |
| 21 | 21 | |
| 22 | +left low. | |
| 22 | 23 | right plus. |
| 23 | 24 | right times. |
| 24 | 25 | left power. |
| ... | ... | @@ -94,6 +95,7 @@ define TokenValue_calc_parser |
| 94 | 95 | { |
| 95 | 96 | failure then eof(unique), |
| 96 | 97 | success(c) then |
| 98 | + if c = '\n' then eof(unique) else | |
| 97 | 99 | if c = '(' then _lpar(unique) else |
| 98 | 100 | if c = ')' then _rpar(unique) else |
| 99 | 101 | if c = '+' then _plus(unique) else | ... | ... |
anubis_dev/library/syntactic_analysis/parser_maker.anubis
| ... | ... | @@ -2284,11 +2284,11 @@ define (List((String,List(ExToken))),Int32) |
| 2284 | 2284 | |
| 2285 | 2285 | A -> uv |
| 2286 | 2286 | |
| 2287 | - then it is possible that after having read an instance of v, we reduce using that | |
| 2288 | - rule. Furthermore, the automaton is able to look at the next token to be read (it has | |
| 2289 | - one token of 'lookahead'). This helps to make decisions, as we will see later, using | |
| 2290 | - precedence and association rules. In particular, the automaton knows which token is | |
| 2291 | - allowded as the lookahead for a given reduction. | |
| 2287 | + then it is possible that after a further reading of an instance of v, we reduce using | |
| 2288 | + that rule. Furthermore, the automaton is able to look at the next token to be read (it | |
| 2289 | + has one token of 'lookahead'). This helps to make decisions, as we will see later, | |
| 2290 | + using precedence and association rules. In particular, the automaton knows which token | |
| 2291 | + is allowded as the lookahead for a given reduction. | |
| 2292 | 2292 | |
| 2293 | 2293 | Hence, we introduce the notion of a scenario. A 'scenario' is a pair, denoted (in these |
| 2294 | 2294 | explanations): |
| ... | ... | @@ -2385,10 +2385,8 @@ type Scenario: |
| 2385 | 2385 | |
| 2386 | 2386 | |
| 2387 | 2387 | |
| 2388 | - | |
| 2389 | - | |
| 2390 | - | |
| 2391 | - | |
| 2388 | + | |
| 2389 | + | |
| 2392 | 2390 | |
| 2393 | 2391 | *** (3.4) Testing for similarity. |
| 2394 | 2392 | |
| ... | ... | @@ -3322,8 +3320,6 @@ define List(IntermediateState) |
| 3322 | 3320 | are called 'reducing' scenarii, because they call for a reduction. |
| 3323 | 3321 | |
| 3324 | 3322 | |
| 3325 | - type NonEmptyList($T): | |
| 3326 | - [$T . List($T)]. | |
| 3327 | 3323 | |
| 3328 | 3324 | type ShiftingScenario: |
| 3329 | 3325 | shifting_scenario(Int32 id, |
| ... | ... | @@ -4483,7 +4479,9 @@ define One |
| 4483 | 4479 | List(SymbolType) types_table, |
| 4484 | 4480 | List((ExSymbol,Int32)) transitions, |
| 4485 | 4481 | List(ShiftingScenario) ss, |
| 4486 | - List(Option) options | |
| 4482 | + List(Option) options, | |
| 4483 | + String state_id, | |
| 4484 | + Int32 num_args | |
| 4487 | 4485 | ) = |
| 4488 | 4486 | if types_table is |
| 4489 | 4487 | { |
| ... | ... | @@ -4491,20 +4489,29 @@ define One |
| 4491 | 4489 | [h . t] then if h is symtype(sym,type) then |
| 4492 | 4490 | if sym is |
| 4493 | 4491 | { |
| 4494 | - token(name) then print_restart_cases(t,transitions,ss,options), | |
| 4492 | + token(name) then print_restart_cases(t,transitions,ss,options,state_id,num_args), | |
| 4495 | 4493 | non_terminal(name) then |
| 4496 | - print(right_pad(" "+name+"(value)",40)+" then "); | |
| 4494 | + print(right_pad(" "+name+"(value)",20)+" then "); | |
| 4497 | 4495 | (if member(verbose,options) |
| 4498 | - then print("print(\"Got a '"+name+"'\\n\");\n ") | |
| 4496 | + then print("print(\"Got a '"+name+"'\\n\");\n ") | |
| 4499 | 4497 | else unique); |
| 4500 | 4498 | if find_transition(name,transitions) is |
| 4501 | 4499 | { |
| 4502 | - failure then print("alert\n") | |
| 4503 | - success(p) then print("state_"+integer_to_string(p)+"(input,value,"+ | |
| 4500 | + failure then if state_id = "0" | |
| 4501 | + then print("end_ret(start(value))\n") // accept | |
| 4502 | + else print("alert\n"), | |
| 4503 | + success(p) then | |
| 4504 | + print("if state_"+integer_to_string(p)+"(input,value,"+ | |
| 4504 | 4505 | format_restart_case_args( |
| 4505 | - length(get_longuest_stack_for(name,ss))-1)+")\n") | |
| 4506 | + length(get_longuest_stack_for(name,ss))-1)+") is\n"); | |
| 4507 | + print(" {\n"); | |
| 4508 | + print(" error(a,b) then error(a,b),\n"); | |
| 4509 | + print(" end_ret(v) then restart_"+state_id+"(input,v,"+ | |
| 4510 | + format_restart_case_args(num_args)+"),\n"); | |
| 4511 | + print(" do_ret(v) then v,\n"); | |
| 4512 | + print(" }\n") | |
| 4506 | 4513 | }; |
| 4507 | - print_restart_cases(t,transitions,ss,options) | |
| 4514 | + print_restart_cases(t,transitions,ss,options,state_id,num_args) | |
| 4508 | 4515 | } |
| 4509 | 4516 | }. |
| 4510 | 4517 | |
| ... | ... | @@ -4654,7 +4661,7 @@ define One |
| 4654 | 4661 | else unique); |
| 4655 | 4662 | print(" if result is\n"); |
| 4656 | 4663 | print(" {\n"); |
| 4657 | - print_restart_cases(types_table,tr,ss,options); | |
| 4664 | + print_restart_cases(types_table,tr,ss,options,n,length(stack)-1); | |
| 4658 | 4665 | print(" }.\n"); |
| 4659 | 4666 | |
| 4660 | 4667 | print("\n\ndefine Ret(NonTerminalValue)\n"); |
| ... | ... | @@ -5084,7 +5091,7 @@ define One |
| 5084 | 5091 | else unique); |
| 5085 | 5092 | print(" "+put_do_ret( |
| 5086 | 5093 | head+"("+term+")", |
| 5087 | - length(body)-1 | |
| 5094 | + length(body) | |
| 5088 | 5095 | )+".\n") |
| 5089 | 5096 | ) |
| 5090 | 5097 | ); | ... | ... |
anubis_dev/library/system/parameter/inifile.anubis
| ... | ... | @@ -146,7 +146,7 @@ define One parseSection (String line, IniInfo ini ) = |
| 146 | 146 | if sub_string(line, 1, idx-1) is |
| 147 | 147 | { |
| 148 | 148 | failure then alert |
| 149 | - success(section) then addSection(ini, section); | |
| 149 | + success(section) then addSection(ini, section) | |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | . |
| ... | ... | @@ -231,14 +231,14 @@ public define IniInfo loadIniFile( String fileName) = |
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | |
| 234 | -type IniLine: | |
| 234 | + type IniLine: | |
| 235 | 235 | eof, |
| 236 | 236 | blank, |
| 237 | 237 | section_header(String name), |
| 238 | 238 | variable(String name, String value), |
| 239 | 239 | comment(String). |
| 240 | 240 | |
| 241 | -define IniLine parseIniLine (String line) = | |
| 241 | + define IniLine parseIniLine (String line) = | |
| 242 | 242 | if nth(0,line) is |
| 243 | 243 | { |
| 244 | 244 | failure then blank, |
| ... | ... | @@ -250,22 +250,22 @@ define IniLine parseIniLine (String line) = |
| 250 | 250 | else variable(parseVarLine(line)) |
| 251 | 251 | }. |
| 252 | 252 | |
| 253 | -define IniLine parseIniLine (Stream s) = | |
| 253 | + define IniLine parseIniLine (Stream s) = | |
| 254 | 254 | if read_line(s) is |
| 255 | 255 | { |
| 256 | 256 | failure then eof, |
| 257 | 257 | success(l) then parseIniLine(l) |
| 258 | 258 | }. |
| 259 | 259 | |
| 260 | -type IniVar: | |
| 260 | + type IniVar: | |
| 261 | 261 | iniVar(String name, |
| 262 | 262 | Var(String) value). |
| 263 | 263 | |
| 264 | -type IniSection: | |
| 264 | + type IniSection: | |
| 265 | 265 | iniSection(String name, |
| 266 | 266 | Var(List(IniVar)) content). |
| 267 | 267 | |
| 268 | -type IniInfo: | |
| 268 | + type IniInfo: | |
| 269 | 269 | iniInfo(String fileName, |
| 270 | 270 | Var(List(IniSection)) content). |
| 271 | 271 | ... | ... |