Class: Vertigo::Parser
- Inherits:
-
GenericParser
- Object
- GenericParser
- Vertigo::Parser
- Defined in:
- lib/vertigo/parser.rb
Constant Summary collapse
- ADDITIV_OP =
xor ?
[:add,:sub, :or, :xor,:xnor, :nor]
- MULTITIV_OP =
exp ?
[:mul,:div,:mod,:and,:nand,:shiftr,:shiftl,:exp]
- COMPARISON_OP =
[:eq,:neq,:gt,:gte,:lt,:lte,:leq]
Instance Attribute Summary collapse
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#lexer ⇒ Object
Returns the value of attribute lexer.
-
#options ⇒ Object
Returns the value of attribute options.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
- #after? ⇒ Boolean
- #aggregated? ⇒ Boolean
- #attributed? ⇒ Boolean
- #concat? ⇒ Boolean
- #consume_to(token_kind) ⇒ Object
-
#fix_corner_case(e) ⇒ Object
z(0) := or (rs(15 downto 0)); zero := not (or e_in.write_data);.
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #initialized? ⇒ Boolean
-
#isolated_range? ⇒ Boolean
—————————————————————–^ !!!! ..^.…..
- #lex(filename) ⇒ Object
- #mapped? ⇒ Boolean
- #parenthesized? ⇒ Boolean
- #parse(filename) ⇒ Object
- #parse_additive ⇒ Object
- #parse_aggregate_part ⇒ Object
- #parse_alias ⇒ Object
-
#parse_archi_body ⇒ Object
.
- #parse_archi_decls ⇒ Object
- #parse_architecture ⇒ Object
- #parse_array_decl ⇒ Object
- #parse_array_dim_decl ⇒ Object
- #parse_array_dim_decls ⇒ Object
- #parse_assert ⇒ Object
- #parse_assign ⇒ Object
- #parse_attribute ⇒ Object
-
#parse_body ⇒ Object
body.
- #parse_case ⇒ Object
- #parse_comparative ⇒ Object
- #parse_component_decl ⇒ Object
- #parse_component_instanciation ⇒ Object
- #parse_concurrent_stmt ⇒ Object
-
#parse_configuration ⇒ Object
configuration.
- #parse_configuration_body ⇒ Object
- #parse_configuration_for ⇒ Object
- #parse_constant ⇒ Object
- #parse_decls ⇒ Object
- #parse_discrete_range ⇒ Object
- #parse_else ⇒ Object
- #parse_elsif ⇒ Object
- #parse_entity ⇒ Object
- #parse_entity_instanciation ⇒ Object
- #parse_entity_spec ⇒ Object
- #parse_enum ⇒ Object
-
#parse_exit ⇒ Object
EXIT [ loop_label ] [ WHEN condition ] ;.
-
#parse_expression ⇒ Object
expression ===============================.
- #parse_for ⇒ Object
- #parse_for_generate ⇒ Object
- #parse_formal_arg ⇒ Object
- #parse_formal_args ⇒ Object
- #parse_function ⇒ Object
- #parse_generic ⇒ Object
- #parse_generic_map? ⇒ Boolean
- #parse_generics? ⇒ Boolean
- #parse_if_generate ⇒ Object
- #parse_if_stmt ⇒ Object
- #parse_io ⇒ Object
- #parse_label? ⇒ Boolean
- #parse_library ⇒ Object
-
#parse_loop ⇒ Object
unusual loop…end loop.
- #parse_map ⇒ Object
- #parse_multiplicative ⇒ Object
- #parse_null_stmt ⇒ Object
-
#parse_package ⇒ Object
package.
- #parse_package_body ⇒ Object
- #parse_package_decl ⇒ Object
-
#parse_parenth ⇒ Object
parenthesized expressions (NOT indexed or funcall).
- #parse_port_map? ⇒ Boolean
- #parse_ports ⇒ Object
- #parse_procedure ⇒ Object
- #parse_process ⇒ Object
- #parse_record ⇒ Object
- #parse_record_items ⇒ Object
- #parse_report ⇒ Object
- #parse_return ⇒ Object
- #parse_select ⇒ Object
- #parse_selected_when ⇒ Object
- #parse_sensitivity_list ⇒ Object
- #parse_seq_stmt ⇒ Object
- #parse_severity ⇒ Object
- #parse_signal ⇒ Object
- #parse_term ⇒ Object
-
#parse_type ⇒ Object
- do accept
-
signal a_outputs : A_lib.A_pkg.outputs_t;.
- #parse_typedecl ⇒ Object
- #parse_unary ⇒ Object
- #parse_use ⇒ Object
- #parse_variable ⇒ Object
- #parse_wait ⇒ Object
- #parse_when_case ⇒ Object
- #parse_while ⇒ Object
- #print_tokens(n) ⇒ Object
- #qualified? ⇒ Boolean
- #ranged_type? ⇒ Boolean
- #selected_name? ⇒ Boolean
- #timed? ⇒ Boolean
Methods inherited from GenericParser
#acceptIt, #expect, #lookahead, #maybe, #more?, #next_tokens, #niy, #showNext
Constructor Details
#initialize(options = {}) ⇒ Parser
Returns a new instance of Parser.
13 14 15 |
# File 'lib/vertigo/parser.rb', line 13 def initialize ={} @options= end |
Instance Attribute Details
#basename ⇒ Object
Returns the value of attribute basename.
11 12 13 |
# File 'lib/vertigo/parser.rb', line 11 def basename @basename end |
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/vertigo/parser.rb', line 11 def filename @filename end |
#lexer ⇒ Object
Returns the value of attribute lexer.
10 11 12 |
# File 'lib/vertigo/parser.rb', line 10 def lexer @lexer end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/vertigo/parser.rb', line 9 def @options end |
#tokens ⇒ Object
Returns the value of attribute tokens.
10 11 12 |
# File 'lib/vertigo/parser.rb', line 10 def tokens @tokens end |
Instance Method Details
#after? ⇒ Boolean
1433 1434 1435 1436 1437 1438 1439 1440 |
# File 'lib/vertigo/parser.rb', line 1433 def after? if showNext.is_a?(:after) ret=After.new acceptIt ret.rhs=parse_expression return ret end end |
#aggregated? ⇒ Boolean
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 |
# File 'lib/vertigo/parser.rb', line 1317 def aggregated? if showNext.is_a? [:comma] ret=Aggregate.new ret.pos=showNext.pos while showNext.is_a?(:comma) acceptIt ret << parse_aggregate_part end return ret end end |
#attributed? ⇒ Boolean
1451 1452 1453 1454 1455 1456 1457 |
# File 'lib/vertigo/parser.rb', line 1451 def attributed? if showNext.is_a?(:attribute_literal) ret=Attributed.new ret.rhs=acceptIt return ret end end |
#concat? ⇒ Boolean
1442 1443 1444 1445 1446 1447 1448 1449 |
# File 'lib/vertigo/parser.rb', line 1442 def concat? if showNext.is_a?(:ampersand) ret=Concat.new acceptIt ret.rhs=parse_expression return ret end end |
#consume_to(token_kind) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/vertigo/parser.rb', line 71 def consume_to token_kind while showNext && showNext.kind!=token_kind acceptIt end if showNext.nil? raise "cannot find token '#{token_kind}'" end end |
#fix_corner_case(e) ⇒ Object
z(0) := or (rs(15 downto 0)); zero := not (or e_in.write_data);
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 |
# File 'lib/vertigo/parser.rb', line 1186 def fix_corner_case e case e when Binary if e.lhs.nil? ret=FuncCall.new ret.name=Ident.new(Vertigo::Token.create(:ident,e.op.val)) case parenth=e.rhs when Parenth ret.actual_args=[parenth.expr].flatten else ret.actual_args=[e.rhs].flatten end return ret end end e end |
#initialized? ⇒ Boolean
1426 1427 1428 1429 1430 1431 |
# File 'lib/vertigo/parser.rb', line 1426 def initialized? if showNext.is_a?(:vassign) acceptIt return parse_expression end end |
#isolated_range? ⇒ Boolean
—————————————————————–^ !!!! ..^.….. req_laddr <= r0.addr(63 downto LINE_OFF_BITS) & (LINE_OFF_BITS-1 downto 0 => ‘0’); ————————————————[ expr ] NOT used ?
1349 1350 1351 1352 1353 1354 1355 1356 |
# File 'lib/vertigo/parser.rb', line 1349 def isolated_range? if showNext.is_a? [:downto,:to] acceptIt ret=IsolatedRange.new ret.rhs=parse_expression return ret end end |
#lex(filename) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vertigo/parser.rb', line 17 def lex filename unless File.exists?(filename) raise "ERROR : cannot find file '#{filename}'" end begin str=IO.read(filename).downcase tokens=Lexer.new.tokenize(str) tokens=tokens.select{|t| t.class==Token} # filters [nil,nil,nil] tokens.reject!{|tok| tok.is_a? [:comment,:newline,:space]} return tokens rescue Exception=>e unless [:mute] puts e.backtrace puts e end raise "an error occured during LEXICAL analysis. Sorry. Aborting." end end |
#mapped? ⇒ Boolean
1358 1359 1360 1361 1362 1363 1364 1365 |
# File 'lib/vertigo/parser.rb', line 1358 def mapped? if showNext.is_a?(:imply) acceptIt ret=Map.new ret.rhs=parse_expression return ret end end |
#parenthesized? ⇒ Boolean
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 |
# File 'lib/vertigo/parser.rb', line 1399 def parenthesized? if showNext.is_a? :lparen acceptIt ret=FuncCall.new args=[] while !showNext.is_a? :rparen args << parse_map() while showNext.is_a? :comma acceptIt args << parse_map() end ret.actual_args = args if showNext.is_a? [:downto,:to] #finally this was a Sliced ! ret=Sliced.new ret.dir=acceptIt ret.rhs=parse_expression ret.lhs=args.first end end expect :rparen return ret else return false end end |
#parse(filename) ⇒ Object
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 |
# File 'lib/vertigo/parser.rb', line 36 def parse filename begin @tokens=lex(filename) root=Root.new([]) while @tokens.any? case showNext.kind when :comment root << acceptIt when :library root << parse_library when :use root << parse_use when :entity root << parse_entity when :architecture root << parse_architecture when :package root << parse_package when :configuration root << parse_configuration else raise "got #{showNext}" end end rescue Exception => e unless [:mute] puts e.backtrace puts e end raise end root.flatten! root end |
#parse_additive ⇒ Object
1205 1206 1207 1208 1209 1210 1211 1212 1213 |
# File 'lib/vertigo/parser.rb', line 1205 def parse_additive t1=parse_multiplicative while more? && showNext.is_a?(ADDITIV_OP) op=acceptIt #full token t2=parse_multiplicative t1=Binary.new(t1,op,t2) end return t1 end |
#parse_aggregate_part ⇒ Object
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 |
# File 'lib/vertigo/parser.rb', line 1329 def parse_aggregate_part ret=parse_expression if showNext.is_a? [:downto,:to] dr=DiscreteRange.new dr.lhs=ret dr.dir=acceptIt dr.rhs=parse_expression ret=dr end if map=mapped? map.lhs=ret ret=map end ret end |
#parse_alias ⇒ Object
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/vertigo/parser.rb', line 597 def parse_alias ret=Alias.new # or ret=[] as for variable ? expect :alias ret.designator=Ident.new(expect :ident) # Warn : see designator in IEEE expect :colon ret.type=parse_type expect :is ret.name=Ident.new(expect :ident) ret.signature=nil #NIY unless showNext.is_a?(:semicolon) raise "ERROR : parse alias (signature not implemented yet)" end expect :semicolon ret end |
#parse_archi_body ⇒ Object
613 614 615 616 617 618 619 620 621 622 623 624 |
# File 'lib/vertigo/parser.rb', line 613 def parse_archi_body ret=Body.new expect :begin while !showNext.is_a?(:end) ret << parse_concurrent_stmt end expect :end maybe :architecture maybe :ident expect :semicolon ret end |
#parse_archi_decls ⇒ Object
264 265 266 |
# File 'lib/vertigo/parser.rb', line 264 def parse_archi_decls parse_decls end |
#parse_architecture ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/vertigo/parser.rb', line 252 def parse_architecture archi=Architecture.new expect :architecture archi.name=expect(:ident) expect :of archi.entity_name=expect(:ident) expect :is archi.decls=parse_archi_decls archi.body=parse_archi_body archi end |
#parse_array_decl ⇒ Object
388 389 390 391 392 393 394 395 396 397 |
# File 'lib/vertigo/parser.rb', line 388 def parse_array_decl ret=ArrayDecl.new expect :array expect :lparen ret.dim_decls=parse_array_dim_decls expect :rparen expect :of ret.type=parse_type ret end |
#parse_array_dim_decl ⇒ Object
409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/vertigo/parser.rb', line 409 def parse_array_dim_decl ret=ArrayDimDecl.new case showNext.kind when :natural,:integer,:positive ret.type_mark=acceptIt expect :range ret.range=expect(:urange) else ret.range=parse_discrete_range # puts "ERROR : niy at #{showNext.pos}" # niy end ret end |
#parse_array_dim_decls ⇒ Object
399 400 401 402 403 404 405 406 407 |
# File 'lib/vertigo/parser.rb', line 399 def parse_array_dim_decls ret=[] ret << parse_array_dim_decl while showNext.is_a?(:comma) #multi dimensions acceptIt ret << parse_array_dim_decl end ret end |
#parse_assert ⇒ Object
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'lib/vertigo/parser.rb', line 1129 def parse_assert ret=Assert.new expect :assert ret.cond=parse_expression if showNext.is_a?(:report) ret.report=parse_report end if showNext.is_a?(:severity) ret.severity=parse_severity end expect(:semicolon) unless ret.report ret end |
#parse_assign ⇒ Object
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
# File 'lib/vertigo/parser.rb', line 959 def parse_assign lhs=parse_term if showNext.is_a? [:vassign,:leq,:semicolon] case showNext.kind when :vassign acceptIt ret=VarAssign.new(lhs) when :leq acceptIt ret=SigAssign.new(lhs) when :semicolon #assign? No ! Procedure call ! acceptIt ret=ProcedureCall.new ret.name=lhs ret.actual_args=[] return ret end end ret.rhs=rhs=parse_expression case showNext.kind when :comma ret.rhs=wfm=Waveform.new wfm.elements << rhs while showNext.is_a?(:comma) acceptIt wfm.elements << parse_expression end when :when ret.rhs=cond=CondExpr.new while showNext.is_a?(:when) #cond assign cond.whens << when_=When.new got_when=true acceptIt when_.expr=rhs when_.cond=parse_expression expect :else rhs=parse_expression end cond.else_=rhs when :semicolon # pp showNext # ret.rhs=rhs else raise "unexpected error in parse assign : #{showNext.val}, at #{showNext.pos}" end expect :semicolon ret end |
#parse_attribute ⇒ Object
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/vertigo/parser.rb', line 544 def parse_attribute expect :attribute name=Ident.new(expect :ident) case showNext.kind when :colon #declaration ret=AttributeDecl.new ret.name=name acceptIt ret.type=parse_type when :of # specification ret=AttributeSpec.new ret.name=name acceptIt ret.entity_spec=parse_entity_spec expect :is ret.expr=parse_expression else raise "ERROR : parse attribute error at line #{showNext.line} #{showNext}" end expect :semicolon ret end |
#parse_body ⇒ Object
body
910 911 912 913 914 915 916 |
# File 'lib/vertigo/parser.rb', line 910 def parse_body ret=Body.new while !showNext.is_a?(:end) and !showNext.is_a?(:elsif) and !showNext.is_a?(:else) and !showNext.is_a?(:when) ret << parse_seq_stmt end ret end |
#parse_case ⇒ Object
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/vertigo/parser.rb', line 1058 def parse_case ret=Case.new expect :case ret.expr=parse_expression expect :is while showNext.is_a? :when ret << parse_when_case end expect :end expect :case expect :semicolon ret end |
#parse_comparative ⇒ Object
1227 1228 1229 1230 1231 1232 1233 1234 1235 |
# File 'lib/vertigo/parser.rb', line 1227 def parse_comparative t1=parse_term while more? && showNext.is_a?(COMPARISON_OP) op=acceptIt t2=parse_term t1=Binary.new(t1,op,t2) end return t1 end |
#parse_component_decl ⇒ Object
531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/vertigo/parser.rb', line 531 def parse_component_decl ret=ComponentDecl.new expect :component ret.name=Ident.new(expect :ident) maybe :is ret.generics=parse_generics? ret.ports=parse_ports expect :end expect :component expect :semicolon ret end |
#parse_component_instanciation ⇒ Object
700 701 702 703 704 705 706 707 708 |
# File 'lib/vertigo/parser.rb', line 700 def parse_component_instanciation ret=ComponentInstance.new maybe :component ret.name=expect :ident ret.generic_map=parse_generic_map? ret.port_map=parse_port_map? expect :semicolon ret end |
#parse_concurrent_stmt ⇒ Object
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/vertigo/parser.rb', line 626 def parse_concurrent_stmt label=parse_label? case showNext.kind when :process ret=parse_process when :entity ret=parse_entity_instanciation when :ident # assign or component instanciation case lookahead(2).kind when :port,:generic ret=parse_component_instanciation else ret=parse_assign end when :component ret=parse_component_instanciation when :with ret=parse_select when :if ret=parse_if_generate when :assert ret=parse_assert when :for ret=parse_for_generate else raise "parse_concurrent_stmt : #{pp showNext}" end ret.label=label if label ret end |
#parse_configuration ⇒ Object
configuration
881 882 883 884 885 886 887 888 889 890 891 |
# File 'lib/vertigo/parser.rb', line 881 def parse_configuration expect :configuration expect :ident expect :of expect :ident expect :is parse_configuration_body expect :end expect :ident expect :semicolon end |
#parse_configuration_body ⇒ Object
893 894 895 896 897 898 899 900 |
# File 'lib/vertigo/parser.rb', line 893 def parse_configuration_body case showNext.kind when :for parse_configuration_for else raise "ERROR : configurations not fully supported. Sorry." end end |
#parse_configuration_for ⇒ Object
902 903 904 905 906 907 908 |
# File 'lib/vertigo/parser.rb', line 902 def parse_configuration_for expect :for expect :ident expect :end expect :for expect :semicolon end |
#parse_constant ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/vertigo/parser.rb', line 298 def parse_constant ret=[] expect :constant ret << cst=Constant.new cst.name=Ident.new(expect :ident) while showNext.is_a?(:comma) acceptIt ret << cst=Constant.new cst.name=Ident.new(expect :ident) end expect :colon type=parse_type ret.each{|cst| cst.type=type} expect :vassign ret.last.expr=parse_expression expect :semicolon ret end |
#parse_decls ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/vertigo/parser.rb', line 268 def parse_decls decls=[] while showNext.kind!=:begin and showNext.kind!=:end case showNext.kind when :constant decls << parse_constant when :type,:subtype decls << parse_typedecl when :signal decls << parse_signal when :procedure decls << parse_procedure when :function,:impure decls << parse_function when :component decls << parse_component_decl when :attribute decls << parse_attribute when :variable decls << parse_variable when :alias decls << parse_alias else raise "ERROR : parse_decls #{pp showNext}" end end decls.flatten! decls end |
#parse_discrete_range ⇒ Object
242 243 244 245 246 247 248 249 250 |
# File 'lib/vertigo/parser.rb', line 242 def parse_discrete_range e1=parse_expression if showNext.is_a? [:downto,:to] dir=acceptIt e2=parse_expression return DiscreteRange.new(e1,dir,e2) end e1 end |
#parse_else ⇒ Object
1037 1038 1039 1040 1041 1042 |
# File 'lib/vertigo/parser.rb', line 1037 def parse_else ret=Else.new expect :else ret.body=parse_body ret end |
#parse_elsif ⇒ Object
1028 1029 1030 1031 1032 1033 1034 1035 |
# File 'lib/vertigo/parser.rb', line 1028 def parse_elsif ret=Elsif.new expect :elsif ret.cond=parse_expression expect :then ret.body=parse_body ret end |
#parse_entity ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vertigo/parser.rb', line 108 def parse_entity entity=Entity.new expect :entity entity.name=Ident.new(expect :ident) expect :is entity.generics=parse_generics? if showNext.is_a? :port entity.ports=parse_ports end expect :end maybe :entity maybe :ident expect :semicolon return entity end |
#parse_entity_instanciation ⇒ Object
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/vertigo/parser.rb', line 728 def parse_entity_instanciation ret=EntityInstance.new expect :entity ret.full_name=parse_term # now ENSURE :selected_name case fc=ret.full_name when FuncCall ret.full_name=fc.name ret.arch_name=fc.actual_args.first end if showNext.is_a?(:lparen) acceptIt ret.arch_name=Ident.new(expect :ident) expect :rparen end ret.generic_map=parse_generic_map? ret.port_map=parse_port_map? expect :semicolon ret end |
#parse_entity_spec ⇒ Object
567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/vertigo/parser.rb', line 567 def parse_entity_spec ret=EntitySpec.new ret.elements << Ident.new(expect :ident) while showNext.is_a?(:comma) acceptit ret.elements << Ident.new(expect :ident) end expect :colon ret.entity_class=acceptIt # entity,procedure, architecture etc... ret end |
#parse_enum ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/vertigo/parser.rb', line 346 def parse_enum ret=EnumDecl.new expect :lparen ret << Ident.new(expect :ident) while showNext.is_a?(:comma) acceptIt ret << Ident.new(expect :ident) end expect :rparen ret end |
#parse_exit ⇒ Object
EXIT [ loop_label ] [ WHEN condition ] ;
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 |
# File 'lib/vertigo/parser.rb', line 1165 def parse_exit expect :exit if showNext.is_a?(:ident) acceptIt end if showNext.is_a?(:when) acceptIt parse_expression end expect :semicolon end |
#parse_expression ⇒ Object
expression ===============================
1178 1179 1180 1181 1182 |
# File 'lib/vertigo/parser.rb', line 1178 def parse_expression e=parse_additive e=fix_corner_case(e) # things like => zero := not (or e_in.write_data); e end |
#parse_for ⇒ Object
1044 1045 1046 1047 1048 1049 1050 |
# File 'lib/vertigo/parser.rb', line 1044 def parse_for expect :for expect :ident expect :in parse_discrete_range parse_loop end |
#parse_for_generate ⇒ Object
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 |
# File 'lib/vertigo/parser.rb', line 814 def parse_for_generate ret=ForGenerate.new expect :for ret.index=Ident.new(acceptIt) expect :in ret.range=parse_discrete_range expect :generate while showNext.is_not_a?(:begin) parse_decls end ret.body=body=Body.new expect :begin while !showNext.is_a?(:end) body << parse_concurrent_stmt end expect :end expect :generate expect :semicolon ret end |
#parse_formal_arg ⇒ Object
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/vertigo/parser.rb', line 476 def parse_formal_arg ret=[] is_signal=(maybe :signal) ret << fp=FormalArg.new fp.name=Ident.new(expect :ident) while showNext.is_a?(:comma) acceptIt ret << fp=FormalArg.new fp.name=Ident.new(expect :ident) end expect :colon if showNext.is_a? [:in,:out,:inout] direction=acceptIt end type=parse_type ret.each{|fp| fp.direction=direction fp.type=type } ret end |
#parse_formal_args ⇒ Object
465 466 467 468 469 470 471 472 473 474 |
# File 'lib/vertigo/parser.rb', line 465 def parse_formal_args ret=[] ret << parse_formal_arg while showNext.is_a?(:semicolon) acceptIt ret << parse_formal_arg end ret.flatten! ret end |
#parse_function ⇒ Object
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/vertigo/parser.rb', line 498 def parse_function ret=FuncDecl.new maybe :impure expect :function ret.name=Ident.new(expect :ident) if showNext.is_a?(:lparen) acceptIt ret.formal_args=parse_formal_args expect :rparen end expect :return ret.return_type=parse_type unless showNext.is_a?(:semicolon) expect :is ret.decls=parse_decls expect :begin ret.body=parse_body expect :end maybe :function maybe :ident else proto=FuncProtoDecl.new proto.name=ret.name proto.formal_args=ret.formal_args proto.return_type=ret.return_type ret=proto end expect :semicolon ret end |
#parse_generic ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/vertigo/parser.rb', line 143 def parse_generic ids=[] ids << expect(:ident) while showNext.is_a? :comma acceptIt ids << expect(:ident) end expect :colon type=parse_type if showNext.is_a? :vassign acceptIt expr=parse_expression end ids.map{|id| Generic.new(id,type,expr)} end |
#parse_generic_map? ⇒ Boolean
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/vertigo/parser.rb', line 710 def parse_generic_map? if showNext.is_a? :generic ret=GenericMap.new acceptIt expect :map expect :lparen while !showNext.is_a?(:rparen) ret << parse_map if showNext.is_a?(:comma) acceptIt end end expect :rparen return ret end nil end |
#parse_generics? ⇒ Boolean
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/vertigo/parser.rb', line 124 def parse_generics? generics=[] if showNext.is_a? :generic generics=[] expect :generic expect :lparen while showNext.is_not_a? :rparen generics << parse_generic if showNext.is_a? :semicolon acceptIt end end expect :rparen expect :semicolon end generics.flatten! return generics end |
#parse_if_generate ⇒ Object
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 |
# File 'lib/vertigo/parser.rb', line 798 def parse_if_generate #pp @tokens[0..5].map{|t| t.val}.join(' | ') ret=IfGenerate.new expect :if ret.cond=parse_expression expect :generate if showNext.is_a?(:begin) # seems optional! acceptIt end ret.body=parse_concurrent_stmt expect :end expect :generate expect :semicolon ret end |
#parse_if_stmt ⇒ Object
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
# File 'lib/vertigo/parser.rb', line 1010 def parse_if_stmt ret=If.new expect :if ret.cond=parse_expression expect :then ret.body=parse_body while showNext.is_a?(:elsif) ret.elsifs << parse_elsif end if showNext.is_a?(:else) ret.else_=parse_else end expect :end expect :if expect :semicolon ret end |
#parse_io ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/vertigo/parser.rb', line 175 def parse_io ids=[] ids << expect(:ident) while showNext.is_a? :comma acceptIt ids << expect(:ident) end expect :colon if showNext.is_a? [:in,:out,:inout] dir=acceptIt dir=dir.kind end type=parse_type ids.map{|id| case dir when :in Input.new(id,type) when :out Output.new(id,type) when :inout InOut.new(id,type) end } end |
#parse_label? ⇒ Boolean
657 658 659 660 661 662 663 664 |
# File 'lib/vertigo/parser.rb', line 657 def parse_label? if lookahead(2).is_a?(:colon) ret=Label.new ret.ident=Ident.new(expect(:ident)) expect(:colon) return ret end end |
#parse_library ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vertigo/parser.rb', line 80 def parse_library ret=[] expect :library ret << lib=Library.new lib.name=Ident.new(expect :ident) while showNext.is_a?(:comma) acceptIt ret << lib=Library.new lib.name=Ident.new(expect :ident) end expect :semicolon ret end |
#parse_loop ⇒ Object
unusual loop…end loop
1155 1156 1157 1158 1159 1160 1161 1162 |
# File 'lib/vertigo/parser.rb', line 1155 def parse_loop #unusual loop...end loop expect :loop parse_body expect :end expect :loop maybe :ident expect :semicolon end |
#parse_map ⇒ Object
765 766 767 768 769 770 771 772 |
# File 'lib/vertigo/parser.rb', line 765 def parse_map ret=parse_expression if map=mapped? map.lhs=ret ret=map end ret end |
#parse_multiplicative ⇒ Object
1216 1217 1218 1219 1220 1221 1222 1223 1224 |
# File 'lib/vertigo/parser.rb', line 1216 def parse_multiplicative t1=parse_comparative while more? && showNext.is_a?(MULTITIV_OP) op=acceptIt t2=parse_comparative t1=Binary.new(t1,op,t2) end return t1 end |
#parse_null_stmt ⇒ Object
952 953 954 955 956 957 |
# File 'lib/vertigo/parser.rb', line 952 def parse_null_stmt ret=NullStmt.new expect :null expect :semicolon ret end |
#parse_package ⇒ Object
package
836 837 838 839 840 841 842 843 844 845 846 |
# File 'lib/vertigo/parser.rb', line 836 def parse_package expect :package case showNext.kind when :ident ret=parse_package_decl when :body ret=parse_package_body else raise "ERROR : parse_package" end end |
#parse_package_body ⇒ Object
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
# File 'lib/vertigo/parser.rb', line 863 def parse_package_body ret=PackageBody.new expect :body ret.name=Ident.new(expect :ident) expect :is while !showNext.is_a?(:end) ret.decls << parse_decls end ret.decls.flatten! expect :end maybe :package maybe :body maybe :ident expect :semicolon ret end |
#parse_package_decl ⇒ Object
848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/vertigo/parser.rb', line 848 def parse_package_decl ret=Package.new ret.name=Ident.new(expect :ident) expect :is while !showNext.is_a?(:end) ret.decls << parse_decls end ret.decls.flatten! expect :end maybe :package maybe :ident expect :semicolon ret end |
#parse_parenth ⇒ Object
parenthesized expressions (NOT indexed or funcall)
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/vertigo/parser.rb', line 1305 def parse_parenth ret=Parenth.new expect :lparen ret.expr=expr=parse_aggregate_part if aggregate=aggregated? aggregate.elements.unshift expr ret=aggregate end expect :rparen ret end |
#parse_port_map? ⇒ Boolean
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/vertigo/parser.rb', line 748 def parse_port_map? if showNext.is_a?(:port) ret=PortMap.new expect :port expect :map expect :lparen while !showNext.is_a?(:rparen) ret.elements << parse_map if showNext.is_a?(:comma) acceptIt end end expect :rparen return ret end end |
#parse_ports ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/vertigo/parser.rb', line 159 def parse_ports ports=[] expect :port expect :lparen while showNext.is_not_a? :rparen ports << parse_io if showNext.is_a? :semicolon acceptIt end end expect :rparen expect :semicolon ports.flatten! ports end |
#parse_procedure ⇒ Object
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/vertigo/parser.rb', line 443 def parse_procedure ret=ProcedureDecl.new expect :procedure ret.name=Ident.new(expect :ident) if showNext.is_a?(:lparen) acceptIt ret.formal_args=parse_formal_args expect :rparen end if showNext.is_a?(:is) acceptIt ret.decls=parse_decls expect :begin ret.body=parse_body expect :end maybe :procedure maybe :ident end expect :semicolon ret end |
#parse_process ⇒ Object
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'lib/vertigo/parser.rb', line 666 def parse_process ret=Vertigo::Process.new expect :process if showNext.is_a?(:lparen) ret.sensitivity=parse_sensitivity_list end ret.decls=parse_decls ret.decls.flatten! expect :begin ret.body=parse_body expect :end expect :process maybe :ident expect :semicolon ret end |
#parse_record ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/vertigo/parser.rb', line 358 def parse_record ret=RecordDecl.new expect :record while showNext.not_a?(:end) ret.elements << parse_record_items end ret.elements.flatten! expect :end expect :record ret end |
#parse_record_items ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/vertigo/parser.rb', line 370 def parse_record_items ret=[] ret << ri=RecordItem.new # in microwatt => name of the item can be 'error' ! # we simply accept the first token as name ! ri.name=Ident.new(acceptIt) while showNext.is_a?(:comma) acceptIt ret << ri=RecordItem.new ri.name=Ident.new(expect :ident) end expect :colon type=parse_type ret.each{|ri| ri.type=type} expect :semicolon ret end |
#parse_report ⇒ Object
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
# File 'lib/vertigo/parser.rb', line 1108 def parse_report ret=Report.new expect :report ret.expr=parse_expression if showNext.is_a?(:severity) ret.severity=parse_severity end expect :semicolon return ret end |
#parse_return ⇒ Object
1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'lib/vertigo/parser.rb', line 1119 def parse_return ret=Return.new expect :return unless showNext.is_a?(:semicolon) ret.expr=parse_expression end expect :semicolon return ret end |
#parse_select ⇒ Object
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
# File 'lib/vertigo/parser.rb', line 774 def parse_select ret=WithSelect.new expect :with ret.with_expr=parse_expression expect :select ret.assigned=parse_term expect :leq ret.selected_whens << parse_selected_when while showNext.is_a?(:comma) acceptIt ret.selected_whens << parse_selected_when end expect :semicolon ret end |
#parse_selected_when ⇒ Object
790 791 792 793 794 795 796 |
# File 'lib/vertigo/parser.rb', line 790 def parse_selected_when ret=SelectedWhen.new ret.lhs=parse_expression expect :when ret.rhs=parse_expression ret end |
#parse_sensitivity_list ⇒ Object
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/vertigo/parser.rb', line 683 def parse_sensitivity_list ret=Sensitivity.new expect :lparen case showNext.kind when :ident ret << Ident.new(acceptIt) while showNext.is_a?(:comma) acceptIt ret << Ident.new(expect :ident) end when :all # VHDL'08 for Microwatt ! ret << acceptIt end expect :rparen ret end |
#parse_seq_stmt ⇒ Object
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 |
# File 'lib/vertigo/parser.rb', line 918 def parse_seq_stmt #puts "parse_seq_stmt line #{showNext.pos.first}" label=parse_label? case showNext.kind when :null ret=parse_null_stmt when :if ret=parse_if_stmt when :for ret=parse_for when :while ret=parse_while when :case ret=parse_case when :wait ret=parse_wait when :report ret=parse_report when :return ret=parse_return when :assert ret=parse_assert when :loop ret=parse_loop when :exit ret=parse_exit when :ident ret=parse_assign else raise "ERROR : parse_seq_stmt : #{pp showNext}" end ret end |
#parse_severity ⇒ Object
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 |
# File 'lib/vertigo/parser.rb', line 1143 def parse_severity if showNext.is_a?(:severity) ret=Severity.new acceptIt if showNext.is_a? severity=[:warning,:note,:error,:failure] ret.type=acceptIt else raise "ERROR : expecting one of #{severity.join(',')}. Got : #{showNext.val}[#{showNext.kind}]" end end end |
#parse_signal ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/vertigo/parser.rb', line 424 def parse_signal ret=[] expect :signal ret << sig=Signal.new sig.name=Ident.new(expect :ident) while showNext.is_a?(:comma) acceptIt ret << sig=Signal.new sig.name=Ident.new(expect :ident) end expect :colon type=parse_type ret.map{|sig| sig.type=type} init=initialized? ret.last.init=init expect :semicolon ret end |
#parse_term ⇒ Object
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 |
# File 'lib/vertigo/parser.rb', line 1238 def parse_term if showNext.is_a? [:ident,:dot,:integer,:natural,:positive,:decimal_literal,:based_literal,:char_literal,:string_literal,:true,:false,:bit_string_literal,:lparen,:others,:abs,:not,:sub,:open] case showNext.kind when :ident ret=Ident.new(acceptIt) when :lparen ret=parse_parenth when :not,:abs,:sub ret=parse_unary when :decimal_literal ret=IntLit.new(acceptIt) when :char_literal ret=CharLit.new(acceptIt) when :string_literal,:bit_string_literal,:based_literal ret=acceptIt when :true,:false ret=BoolLit.new(acceptIt) when :others ret=acceptIt when :open ret=acceptIt when :integer,:natural,:positive ret=acceptIt else puts "cannot parse term : #{showNext} #{showNext.pos}" end end #pp showNext while showNext && showNext.is_a?([:lbrack,:dot,:attribute_literal,:lparen,:ns,:ps,:ms,:after,:ampersand,:tick]) if par=sliced=parenthesized? case par when FuncCall par.name=ret ret=par when Sliced sliced.expr=ret ret=sliced end elsif selected_name=selected_name? selected_name.lhs=ret ret=selected_name elsif attribute=attributed? attribute.lhs=ret ret=attribute elsif timed=timed? timed.lhs=ret ret=timed elsif after=after? after.lhs=ret ret=after elsif concat=concat? concat.lhs=ret ret=concat elsif qualified=qualified? qualified.lhs=ret ret=qualified end end ret end |
#parse_type ⇒ Object
- do accept
-
signal a_outputs : A_lib.A_pkg.outputs_t;
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/vertigo/parser.rb', line 201 def parse_type case showNext.kind when :ident type=NamedType.new type.ident=Ident.new(acceptIt) while selected_name=selected_name? selected_name.lhs=type.ident type.ident=selected_name end else type=StdType.new type.ident=Ident.new(acceptIt) # natural,... if ranged_type=ranged_type? ranged_type.type=type type=ranged_type end end if showNext.is_a? :lparen old=type type=ArrayType.new type.name=old acceptIt type.discrete_ranges << parse_discrete_range while showNext.is_a?(:comma) # multidim array types acceptIt type.discrete_ranges << parse_discrete_range end expect :rparen end type end |
#parse_typedecl ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/vertigo/parser.rb', line 317 def parse_typedecl ret=TypeDecl.new case showNext.kind when :type acceptIt when :subtype acceptIt ret=SubTypeDecl.new else raise "ERROR : expecting 'type' or 'subtype'" end ret.name=Ident.new(expect :ident) expect :is case showNext.kind when :lparen ret.spec=parse_enum when :record ret.spec=parse_record when :array ret.spec=parse_array_decl when :integer,:natural,:positive,:ident ret.spec=parse_type else raise "parse_typedecl : #{pp showNext}" end expect :semicolon ret end |
#parse_unary ⇒ Object
1385 1386 1387 1388 1389 1390 |
# File 'lib/vertigo/parser.rb', line 1385 def parse_unary if showNext.is_a?([:not,:sub,:abs]) acceptIt parse_expression end end |
#parse_use ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/vertigo/parser.rb', line 94 def parse_use ret=Use.new expect :use selected_name=parse_term #ENSURE selected_name unless selected_name.is_a?(SelectedName) raise "expecting selected name afer 'use'" end ret.library=selected_name.lhs.lhs ret.package=selected_name.lhs.rhs ret.element=selected_name.rhs expect :semicolon ret end |
#parse_variable ⇒ Object
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/vertigo/parser.rb', line 579 def parse_variable ret=[] << var=Variable.new expect :variable var.name=Ident.new(expect :ident) while showNext.is_a?(:comma) acceptIt ret << var=Variable.new var.name=Ident.new(expect :ident) end expect :colon type=parse_type ret.each{|var| var.type=type} init=initialized? ret.last.init=init expect :semicolon ret end |
#parse_wait ⇒ Object
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/vertigo/parser.rb', line 1090 def parse_wait ret=Wait.new expect :wait case showNext.kind when :until acceptIt ret.until_=parse_expression when :for acceptIt ret.for_=parse_expression when :semicolon else raise "parse_wait : #{pp showNext}" end expect :semicolon ret end |
#parse_when_case ⇒ Object
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 |
# File 'lib/vertigo/parser.rb', line 1072 def parse_when_case ret=CaseWhen.new expect :when ret.expr=expr=parse_expression if showNext.is_a?(:bar) alternative=Alternative.new alternative << ret.expr ret.expr=alternative while showNext.is_a?(:bar) acceptIt alternative << parse_expression end end expect :imply ret.body=parse_body ret end |
#parse_while ⇒ Object
1052 1053 1054 1055 1056 |
# File 'lib/vertigo/parser.rb', line 1052 def parse_while expect :while parse_expression parse_loop end |
#print_tokens(n) ⇒ Object
1299 1300 1301 1302 |
# File 'lib/vertigo/parser.rb', line 1299 def print_tokens n require "colorize" pp @tokens[0..n-1].map{|tok| tok.val}.join(" ") end |
#qualified? ⇒ Boolean
1459 1460 1461 1462 1463 1464 1465 1466 |
# File 'lib/vertigo/parser.rb', line 1459 def qualified? if showNext.is_a?(:tick) acceptIt ret=Qualified.new ret.rhs=parse_expression return ret end end |
#ranged_type? ⇒ Boolean
233 234 235 236 237 238 239 240 |
# File 'lib/vertigo/parser.rb', line 233 def ranged_type? if showNext.is_a?(:range) acceptIt ret=RangedType.new ret.range=parse_discrete_range return ret end end |
#selected_name? ⇒ Boolean
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 |
# File 'lib/vertigo/parser.rb', line 1367 def selected_name? while showNext.is_a? [:dot] ret=SelectedName.new acceptIt if showNext.is_a? [:ident,:all] case showNext.kind when :ident ret.rhs=Ident.new(acceptIt) when :all ret.rhs=acceptIt #all end return ret else raise "ERROR : expecting ident or 'all' at #{showNext.pos}" end end end |
#timed? ⇒ Boolean
1392 1393 1394 1395 1396 1397 |
# File 'lib/vertigo/parser.rb', line 1392 def timed? if showNext.is_a? [:ps,:ns,:ms] tok=acceptIt ret=Timed.new(nil,tok) end end |